package com.kfm.service;

import com.kfm.dao.UserInfoDao;
import com.kfm.model.UserInfo;
import com.kfm.utils.Constant;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class UserInfoService {

    UserInfoDao dao;

    public UserInfoService() {
        // 1. 加载配置文件
        try {
            InputStream in = Resources.getResourceAsStream(Constant.MYBATIS_CONFIG);
            // 2. 构建SqlSession
            SqlSession sqlSession = new SqlSessionFactoryBuilder().build(in).openSession();
            // 3. 获取代理对象
            dao = sqlSession.getMapper(UserInfoDao.class);
        } catch (IOException e) {

            e.printStackTrace();
        }
    }

    public List<UserInfo> findAll() {
        return dao.selectAll();
    }
}
